/*global alert, clearInterval: false, clearTimeout: false, document: false, event: false, frames: false, history: false, Image: false, location: false, name: false, navigator: false, Option: false, parent: false, screen: false, setInterval: false, setTimeout: false, window: false, XMLHttpRequest: false */
// Set Focus on element and select all content value
function elSelectFocusWithMsg(el, msg) {
    "use strict";
    el.focus();
    el.select();
    alert(msg);
}

//check Exam name, check on duplicate names ???
function CheckAndSubmit() {
    "use strict";
    var elName, strName, elDuration, intDuration;
    strName = "";
    intDuration = 0;

    // for now, check on strlen != 0	
    elName = document.getElementById("ExamName");
    // strName = parseInt(elName.value);
    strName = elName.value;
    if (strName.length === 0) {
        elSelectFocusWithMsg(elName, "Name field for exam can't be empty.");
        return false;
    }

    // check Duration field
    elDuration = document.getElementById("Duration");
    intDuration = parseInt(elDuration.value, 10);
    if (isNaN(intDuration)) {
        elSelectFocusWithMsg(elDuration, "'Duration' field must be a number.");
        return false;
    }
    if (intDuration <= 0) {
        elSelectFocusWithMsg(elDuration,
            "Duration must have higher value than zero.");
        return false;
    }
    if (intDuration > (8 * 60)) {
        elSelectFocusWithMsg(elDuration,
            "Forbidden by labor union\nPlease lower your stake.");
        return false;
    }
}

//delete single question related to one exam
function DelQuestion() {
    "use strict";
    document.frmExamEdit.submit(); // TODO: ask confirmation for delete action
}
